package top.dark.enbedmq;

import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.usage.StoreUsage;
import org.apache.activemq.usage.SystemUsage;
import org.apache.activemq.usage.TempUsage;

/**
 * Author: Darkn
 * description:
 * Create Time: 2021/5/4 20:58
 */
public class EmbedBroker {
    public static void main(String[] args) throws Exception {
        //ActiveMQ的嵌入式实例broker
        BrokerService brokerService = new BrokerService();
        // 启用broker的JMX监控功能
        brokerService.setUseJmx(true);
        // 设置broker名字
        brokerService.setBrokerName("MyBroker");
        // 是否使用持久化
        brokerService.setPersistent(false);
        SystemUsage systemUsage = brokerService.getSystemUsage();
        StoreUsage storeUsage = systemUsage.getStoreUsage();
        //Store limit 100MB
        storeUsage.setLimit(1024*1024*100);
        TempUsage tempUsage = systemUsage.getTempUsage();
        //Temporary Store limit 100MB
        tempUsage.setLimit(1024*1024*100);
        // 添加连接协议，地址
        brokerService.addConnector("tcp://localhost:61616?trace=false");
        brokerService.start();
        System.in.read();
    }
}
